package com.burgeon.backend.SHOP.rest;
/**
 * openid搜索会员数据
 */

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.SHOPBACKEND.entity.Employee;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class FindUserEmpByOpenid extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public FindUserEmpByOpenid(String ip, String account, String password) {

        this.ip = ip;
        this.account = account;
        this.password = password;

    }

    /**
     * 发送并接收字符创
     *
     * @return
     */

    public Employee getData(String openid) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(openid), url);

        String code = new JSONArray(str).getJSONObject(0).getString("code");
        if (!"0".equals(code)) {
           throw new Exception("获取用户错误");
        }
        String count = new JSONArray(str).getJSONObject(0).getString("count");
        if ("0".equals(count)){
            throw new Exception("未找道用户");
        }
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");
        JSONArray array = jsonArray.getJSONArray(0);

        Employee employee = new Employee();

        return employee;
    }

    private MultiValueMap Data(String openid) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段



        columns.add("'HR_EMPLOYEE_ID;NAME'");//开卡人
        columns.add("'C_STORE_ID;ID'");//店仓Id


       // columns.add("'HR_EMPLOYEE_ID1;NAME'");//服务导购



        params.put("columns", columns);
        params.put("table", "C_VIP");//表名

        HashMap paramss = new HashMap();
        String ac = "'="+openid+"'";
        paramss.put("column", "OPENID2");
        paramss.put("condition", ac);
        params.put("params", paramss);
        params.put("count","true");

        return DATA("Query", params, account, password);
    }

    public static void main(String[] args) {
        FindUserEmpByOpenid g = new FindUserEmpByOpenid("59.110.28.94:90","nea@burgeon.com.cn","burgeon55321");
        try {
            System.err.println(g.getData("oFteI5DqOwdu9DSejvmq0TTmYUs0"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
